#pragma once
#include <iostream>
#include <unistd.h>
#include <pthread.h>
namespace MutexModule
{
    class Mutex
    {
        public:
            Mutex()
            {
               pthread_mutex_init(&mutex,nullptr);
            }
            void lock()
            {
               int n = pthread_mutex_lock(&mutex);    
               (void)n;
            }
            void unlock()
            {
                int n = pthread_mutex_unlock(&mutex);
                (void)n;
            }
            pthread_mutex_t* Get()
            {
                return &mutex;
            }
            ~Mutex()
            {
                pthread_mutex_destroy(&mutex);
            }
        private:
            pthread_mutex_t mutex;
    };

    class MutexProtect
    {

        public:
            MutexProtect(Mutex *_mutex):mutex(_mutex)
            {
                mutex->lock();
            }
            ~MutexProtect()
            {
                mutex->unlock();
            }
        private:
            Mutex* mutex;
    };
}